<?php
namespace jy_weishop;
defined('BY_JYA') or exit('error');
/*
	发货
*/
class express extends \plugin{
	//已发货量
	public function getistotal($ordergoods=array()){
		$istotal=0;
		$list=pdo_getall('jy_weishop_order_express',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$ordergoods['orderid']));
		foreach($list as $gv){
			$gv['goodsinfo']=json_decode($gv['goodsinfo'],true);
			foreach($gv['goodsinfo'] as $v){
				if($v['id']==$ordergoods['id']){
					$istotal +=$v['total'];
				}
			}
		}
		return $istotal;
	}
	public function updata($params=array(),$isfaid=0){
		$params['goodsinfo']=array_values($params['goodsinfo']);
		$data=array(
				'express_id'=>intval($params['express']),
				'expresssn'=>$params['expresssn'],
				'opensend_type'=>$params['opensend_type'],
				'fatype'=>$params['fatype'],
				'content'=>$params['content'],
				'goodsinfo'=>ijson_encode($params['goodsinfo']),
				'express_type'=>$params['express_type'],
				'address'=>ijson_encode($params['address']),
				'sendtype'=>$params['sendtype'],
				'is_peisong'=>$params['is_peisong'],
				'peisong_id'=>$params['peisong_id'],
				'sendtitle'=>$params['sendtitle'],
				'need_setpeisong'=>$params['need_setpeisong'],
				'verifycode'=>$params['verifycode'],
				'ordergoodsid'=>$params['ordergoodsid'],
		);
		if($isfaid){
				$this->update('order_express',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$isfaid));
				return true;
		}else{
				$data['uniacid']=$_SESSION['uniacid'];
				$data['orderid']=$params['order_id']?:$params['orderid'];
				$data['morefa']=$params['morefa'];
				$data['createtime']=TIMESTAMP;
				$this->insert('order_express',$data);
		}
		return '';
	}
	public function cancelfh($order_id=0,$noexi=0){
		$order=pdo_get('jy_weishop_order_express',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$order_id),array('id','opensend_type','openorderid'));
		if($order['opensend_type']==1){
			$res=$this->model('order/dada_api')->cancel_send($order_id,4);
			if($res['state']!=1 && !$noexi){
				exi($res['msg'],'error');
			}
		}elseif($order['opensend_type']==2 && $order['openorderid']){
			$res=model('jy_huolala/huo_api')->cancel_send($order['openorderid'],4);
			if($res['state']!=1 && !$noexi){
				exi($res['msg'],'error');
			}
		}
		return '';
	}
}